package com.turnengine.client.local.upkeep.bean;

import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import com.turnengine.client.local.upkeep.enums.UpkeepConditionType;
import java.io.IOException;

/**
 * The Upkeep Condition Serializer.
 */
public class UpkeepConditionSerializer implements IUpkeepConditionSerializer {

	@Override
	public IUpkeepCondition readObject(IDataReader reader) throws IOException {

		// Read fields
		int upkeepId = reader.readInt();
		UpkeepConditionType type = reader.readEnum(UpkeepConditionType.class, true);
		int conditionId = reader.readInt();
		long conditionAmount = reader.readLong();

		// Create object
		IUpkeepCondition object = new UpkeepCondition();
		object.setUpkeepId(upkeepId);
		object.setType(type);
		object.setConditionId(conditionId);
		object.setConditionAmount(conditionAmount);
		return object;
	}

	public void writeObject(IDataWriter writer, IUpkeepCondition object) throws IOException {

		// Get fields
		int upkeepId = object.getUpkeepId();
		UpkeepConditionType type = object.getType();
		int conditionId = object.getConditionId();
		long conditionAmount = object.getConditionAmount();

		// Write fields
		writer.writeInt(upkeepId);
		writer.writeEnum(type, true);
		writer.writeInt(conditionId);
		writer.writeLong(conditionAmount);
	}
}
